.class public abstract Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;
.super Ljava/lang/Object;
.source "AbstractResponse.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;
    }
.end annotation


# static fields
.field protected static final ERROR_CODE_KEY:Ljava/lang/String; = "code"

.field protected static final ERROR_MESSAGE_KEY:Ljava/lang/String; = "message"


# instance fields
.field protected mErrorCode:Ljava/lang/String;

.field protected mErrorMessage:Ljava/lang/String;

.field protected mErrorType:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

.field protected mResponseBody:Ljava/lang/String;

.field protected mResponseSignature:Ljava/lang/String;

.field protected mResponseStatusCode:I


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 22
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method


# virtual methods
.method public getErrorCode()Ljava/lang/String;
    .locals 1

    .prologue
    .line 210
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorCode:Ljava/lang/String;

    if-eqz v0, :cond_0

    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorCode:Ljava/lang/String;

    :goto_0
    return-object v0

    :cond_0
    const-string v0, ""

    goto :goto_0
.end method

.method public getErrorMessage()Ljava/lang/String;
    .locals 1

    .prologue
    .line 219
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorMessage:Ljava/lang/String;

    if-eqz v0, :cond_0

    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorMessage:Ljava/lang/String;

    :goto_0
    return-object v0

    :cond_0
    const-string v0, ""

    goto :goto_0
.end method

.method public getErrorType()Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;
    .locals 1

    .prologue
    .line 201
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorType:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    return-object v0
.end method

.method public hasErrorStatusCode()Z
    .locals 2

    .prologue
    .line 150
    iget v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mResponseStatusCode:I

    const/16 v1, 0xc8

    if-lt v0, v1, :cond_0

    iget v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mResponseStatusCode:I

    const/16 v1, 0x12b

    if-gt v0, v1, :cond_0

    const/4 v0, 0x0

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x1

    goto :goto_0
.end method

.method public abstract onErrorTriggered()V
.end method

.method public abstract onSuccessfulResponseParsed()V
.end method

.method public parseAndCallListener(Ljava/lang/String;)V
    .locals 2
    .parameter "securityToken"

    .prologue
    .line 178
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorType:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    sget-object v1, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;->ERROR_NO_INTERNET_CONNECTION:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    if-ne v0, v1, :cond_0

    .line 179
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->onErrorTriggered()V

    .line 193
    :goto_0
    return-void

    .line 180
    :cond_0
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->hasErrorStatusCode()Z

    move-result v0

    if-eqz v0, :cond_1

    .line 181
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->parseErrorResponse()V

    .line 182
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->onErrorTriggered()V

    goto :goto_0

    .line 183
    :cond_1
    invoke-virtual {p0, p1}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->verifySignature(Ljava/lang/String;)Z

    move-result v0

    if-nez v0, :cond_2

    .line 184
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->onErrorTriggered()V

    goto :goto_0

    .line 186
    :cond_2
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->parseSuccessfulResponse()V

    .line 187
    iget-object v0, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorType:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    sget-object v1, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;->NO_ERROR:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    if-ne v0, v1, :cond_3

    .line 188
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->onSuccessfulResponseParsed()V

    goto :goto_0

    .line 190
    :cond_3
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->onErrorTriggered()V

    goto :goto_0
.end method

.method public parseErrorResponse()V
    .locals 4

    .prologue
    .line 159
    :try_start_0
    new-instance v1, Lorg/json/JSONObject;

    iget-object v2, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mResponseBody:Ljava/lang/String;

    invoke-direct {v1, v2}, Lorg/json/JSONObject;-><init>(Ljava/lang/String;)V

    .line 160
    .local v1, responseBodyAsJsonObject:Lorg/json/JSONObject;
    const-string v2, "code"

    invoke-virtual {v1, v2}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    iput-object v2, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorCode:Ljava/lang/String;

    .line 161
    const-string v2, "message"

    invoke-virtual {v1, v2}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    iput-object v2, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorMessage:Ljava/lang/String;

    .line 162
    sget-object v2, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;->SERVER_RETURNED_ERROR:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    iput-object v2, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorType:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 168
    .end local v1           #responseBodyAsJsonObject:Lorg/json/JSONObject;
    :goto_0
    return-void

    .line 163
    :catch_0
    move-exception v0

    .line 164
    .local v0, e:Ljava/lang/Exception;
    invoke-virtual {p0}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v2

    .line 165
    const-string v3, "An exception was triggered while parsing error response"

    .line 164
    invoke-static {v2, v3, v0}, Lcom/sponsorpay/sdk/android/utils/SponsorPayLogger;->w(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Exception;)V

    .line 166
    sget-object v2, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;->ERROR_OTHER:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    iput-object v2, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorType:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    goto :goto_0
.end method

.method public abstract parseSuccessfulResponse()V
.end method

.method public setResponseData(ILjava/lang/String;Ljava/lang/String;)V
    .locals 0
    .parameter "responseStatusCode"
    .parameter "responseBody"
    .parameter "responseSignature"

    .prologue
    .line 120
    iput p1, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mResponseStatusCode:I

    .line 121
    iput-object p2, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mResponseBody:Ljava/lang/String;

    .line 122
    iput-object p3, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mResponseSignature:Ljava/lang/String;

    .line 123
    return-void
.end method

.method public verifySignature(Ljava/lang/String;)Z
    .locals 2
    .parameter "securityToken"

    .prologue
    .line 135
    iget-object v1, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mResponseBody:Ljava/lang/String;

    invoke-static {v1, p1}, Lcom/sponsorpay/sdk/android/utils/SignatureTools;->generateSignatureForString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 137
    .local v0, generatedSignature:Ljava/lang/String;
    iget-object v1, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mResponseSignature:Ljava/lang/String;

    invoke-virtual {v0, v1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-nez v1, :cond_0

    .line 138
    sget-object v1, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;->ERROR_INVALID_RESPONSE_SIGNATURE:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    iput-object v1, p0, Lcom/sponsorpay/sdk/android/publisher/AbstractResponse;->mErrorType:Lcom/sponsorpay/sdk/android/publisher/AbstractResponse$RequestErrorType;

    .line 139
    const/4 v1, 0x0

    .line 141
    :goto_0
    return v1

    :cond_0
    const/4 v1, 0x1

    goto :goto_0
.end method
